package com.zhentao.utils.sendmeg;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @author TonySong
 * @date 2024/6/8 0008
 * @time 10:37
 */
@Configuration
public class RedisConfig {


    @Bean
    public RedisTemplate<String,String> redisTemplate(RedisConnectionFactory redisConnectionFactory){
         RedisTemplate<String,String> redisTemplate = new RedisTemplate<>();
         redisTemplate.setConnectionFactory(redisConnectionFactory);
         //key
         redisTemplate.setKeySerializer(new StringRedisSerializer());
         //value
         redisTemplate.setValueSerializer(new StringRedisSerializer());

        //value
         redisTemplate.setHashValueSerializer(RedisSerializer.json());
         redisTemplate.setValueSerializer(RedisSerializer.json());
        return redisTemplate;
    }
}
